package org.liulinlin.sejw.db;

import java.sql.*;
import java.util.List;
import java.util.ArrayList;

public class BoxAllocForm { //extends DataAccessServiceImpl {
	private String id;
	private BoxAllocDetails boxAllocDetails;
	private List<AllocDetails> allocDetails;
	
	public BoxAllocForm() {
		
	}
	public BoxAllocForm(String id) {
		DBConnectionManager connMgr = DBConnectionManager.getInstance();
		Connection con = connMgr.getConnection("shipping_export");
		if (con == null) {
			System.out.println("不能获得数据库连接");
			return;
		}
		
		try {
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery("select * from BoxAllocForm where BAF_ID = '" + id + "'");
		
			rs.next();
			this.id = id;
			boxAllocDetails = new BoxAllocDetails(rs.getInt("BAD_ID"));
			allocDetails = new ArrayList<AllocDetails>();
			
			Statement stmtAD = con.createStatement();
			ResultSet rsAD = stmtAD.executeQuery("select * from AllocDetails where BAF_ID = '" + id + "'");
			while (rsAD.next()) {
				allocDetails.add(new AllocDetails(rsAD.getInt("AD_ID")));
			}
			
			rsAD.close();
			stmtAD.close();
			rs.close();
			stmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		connMgr.freeConnection("shipping_export", con);
		connMgr.release();
	}
	
	public void setId(String id) {
		this.id = id;
	}
	public void setBoxAllocDetails(BoxAllocDetails boxAllocDetails) {
		this.boxAllocDetails = boxAllocDetails;
	}
	public void setAllocDetails(List<AllocDetails> allocDetails) {
		this.allocDetails = allocDetails;
	}
	
	public String getId() {
		return id;
	}
	public BoxAllocDetails getBoxAllocDetails() {
		return boxAllocDetails;
	}
	public List<AllocDetails> getAllocDetails() {
		return allocDetails;
	}
}
